home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / xlib.zip / XLIB.MAN < prev   
Text File  |  1987-07-12  |  16KB  |  529 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.             
  8.             
  9.             
  10.             
  11.             
  12.             
  13.             
  14.             
  15.             
  16.             
  17.             
  18.             
  19.             
  20.             
  21.             
  22.             
  23.             
  24.             
  25.                       Communications and Multitasking Library
  26.                                   For Datalight C
  27.                                          by
  28.                                     Matt Brandt
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.             Overview
  74.             
  75.             This  library   contains  a   multitasking  kernel   and   a
  76.             communications kernel.  The communications kernel allows you
  77.             to control  the com ports of a PC in a simple way but allows
  78.             any  speed   the  com   port  is  capable  of  running.  The
  79.             communications routines are interrupt driven so that even in
  80.             very fast  transfers a  program will  not have  any  trouble
  81.             keeping up. The multitasking kernel allows a program to have
  82.             several apparently  simultaneous execution  threads. This is
  83.             especially  usefull   in  communications  because  there  is
  84.             usually traffic in both directions. A small terminal program
  85.             "mini.c" is  included in  this archive  to  demonstrate  the
  86.             concepts. While  you may  use  the  communications  routines
  87.             without worring  about the  multitasking I  urge you to take
  88.             the time  to understand  the multasking kernel. It will make
  89.             your life  much  easier  for  many  applications,  not  just
  90.             communications. In  the following  pages I  will discuss the
  91.             concepts of the communications and multitasking routines and
  92.             demonstrate how  each routine  is called.  The last  section
  93.             deals with  the example  program mini.c  and  shows  how  it
  94.             works.
  95.             
  96.             This package  is being distributed as shareware. You may try
  97.             it out,  see if  it is  what you want, and if it fits a need
  98.             you have  then I  ask that  you send me 20 dollars. For your
  99.             twenty dollars  you will  get the  complete source  code,  a
  100.             license to  use any  and all  of these  routines in your own
  101.             code for  profit without  any royalties, and the other three
  102.             models (P,D,  and L) of the library. If you do not need this
  103.             package and  do not  use it then you are under no obligation
  104.             to send  me any money. Please feel free to pass this archive
  105.             on in it's original form to friends and BBS's that you think
  106.             might be interested.
  107.             
  108.             If you want to send in a contribution send your check to:
  109.             
  110.                  Matt Brandt
  111.                  PO Box 920337
  112.                  Norcross, GA 30092
  113.             
  114.             Your comments and suggestions are also welcome.
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.             Multitasking Concepts
  140.             
  141.             This library  implements what  is  called  a  non-preemptive
  142.             scheduler. This  means that when one task is running it will
  143.             not be  "preempted" by  a task of higher priority. A task is
  144.             only suspended when it makes one of two tasking calls. It is
  145.             up to  the programmer  to make  sure that  all tasks  get  a
  146.             chance to run. Each task has it's own stack area. The global
  147.             and static  data of  the program  is available to all tasks.
  148.             The task  scheduler does  not "hook"  any interrupts or take
  149.             over any  of the machine resources so any task can return to
  150.             DOS at any time. This will have the effect of killing all of
  151.             the other tasks.
  152.             
  153.             There can  be up  to 32  seperate tasks. The main program is
  154.             assigned task  number zero at program startup. The tasks are
  155.             prioritized by  task number with task zero being the highest
  156.             priority task  and task 31 being the lowest priority. You do
  157.             not  need   to  assign  task  numbers  sequentially.  It  is
  158.             perfectly acceptable  to have  only tasks  zero and  ten for
  159.             instance.  The   scheduler  will  perform  slightly  better,
  160.             however, when  there are  a minimum number of "holes" in the
  161.             task assignments.
  162.             
  163.             Tasks can  syncronize and communicate through signals. It is
  164.             also possible for interrupt service routines to send signals
  165.             to tasks.  There are  32 signals available [0..31]. Any task
  166.             can wait  for a signal. It will then be suspended until that
  167.             signal is sent by another task or an interrupt routine. If a
  168.             signal is  sent and  there is  nobody waiting for it then it
  169.             will be  saved until  the next  wait is performed. That wait
  170.             will not  suspend the  task but  instead  will  receive  the
  171.             signal that  was previously sent. Only one occurance of each
  172.             signal can  be saved.  Multiple unwaited occurrances are the
  173.             same as one unwaited occurrance. More that one task may wait
  174.             for a  given signal.  In  this  case  the  highest  priority
  175.             waiting task will be readied when the signal is sent.
  176.             
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.             The task calls are as follows:
  206.             
  207.             t_create(tasknum,func,stk,stksiz);
  208.             int       tasknum;
  209.             void      (*func)();
  210.             int       *stk;
  211.             int       stksiz;
  212.             
  213.                  This call  creates a task whose task number is given by
  214.                  tasknum. If  a task  is already  running at  that  task
  215.                  number it  is replaced  by the new task. func should be
  216.                  the address  of a  function to  be executed  as the new
  217.                  task. stk  should point to an area of memory and stksiz
  218.                  should be  the size  of the task's stack area in bytes.
  219.                  If a task function returns the task is deleted. The new
  220.                  task is placed in a ready to run state but is not given
  221.                  control until  scheduling occurs  by way of a t_wait or
  222.                  t_yield call. If the new task number is the same as the
  223.                  currently running  task then  this call  will  have  no
  224.                  effect.
  225.                  
  226.                  EXAMPLE:
  227.                  
  228.                       int  t1stk[512];
  229.                  
  230.                       task1()
  231.                       {
  232.                            ..code to do a job
  233.                       }
  234.                       
  235.                       .
  236.                       t_create(1,task1,t1stk,sizeof(t1stk));
  237.                  
  238.             t_kill(tasknum)
  239.             int  tasknum;
  240.             
  241.                  This call  will delete  the task  whose task  number is
  242.                  given by tasknum. If tasknum matches the task number of
  243.                  the currently  running task  the current  task will  be
  244.                  killed and rescheduling will occur.
  245.             
  246.             t_wait(signo)
  247.             int  signo;
  248.                  
  249.                  The task  issuing this  call  will  wait  until  signal
  250.                  number signo  is issued by another task or an interrupt
  251.                  service routine.  If the signal was already issued then
  252.                  the current  task will continue unhindered. When a task
  253.                  suspends  then  the  highest  priority  ready  task  is
  254.                  continued at the point where it left off.
  255.             
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.             t_signal(signo)
  272.             
  273.                  This call  causes an occurrance of signal number signo.
  274.                  The highest  priority task waiting for that signal will
  275.